using UnityEngine;

public class Entity : MonoBehaviour
{
	public static float distTimePriority = 2f;

	private AreaDamage[] areasCache = new AreaDamage[0];

	public float health = 10f;

	[HideInInspector]
	public Collider2D[] collidersBody = new Collider2D[0];

	[HideInInspector]
	public bool isDead;

	[HideInInspector]
	public float timeDeath;

	public AreaDamage[] areas
	{
		get
		{
			if (areasCache.Length == 0 && base.gameObject != null)
			{
				areasCache = base.gameObject.GetComponentsInChildren<AreaDamage>(includeInactive: true);
			}
			return areasCache;
		}
	}

	public virtual bool IsHighPriorityBullet()
	{
		return !IsDeadFrame();
	}

	public void HitTestArea(Vector2 globalPoint, float damage, float addRadius, float scaleRadius)
	{
		for (int i = 0; i < areas.Length; i++)
		{
			if (areas[i] != null)
			{
				areas[i].HitTestPoint(globalPoint, damage, (areas[i].radius + addRadius) * scaleRadius);
			}
		}
	}

	public void HitTestArea(Vector2 globalPoint, float damage)
	{
		for (int i = 0; i < areas.Length; i++)
		{
			if (areas[i] != null)
			{
				areas[i].HitTestPoint(globalPoint, damage);
			}
		}
	}

	public void HitTestArea(Vector2 globalPoint, float damage, string idEvent)
	{
		for (int i = 0; i < areas.Length; i++)
		{
			if (areas[i] != null)
			{
				areas[i].HitTestPoint(globalPoint, damage, areas[i].radius, idEvent);
			}
		}
	}

	public float HealthDamage(float damage, float health)
	{
		health = Mathf.Max(0f, health - damage);
		if (!isDead && health == 0f)
		{
			Death();
		}
		return health;
	}

	public float HealthDamage(float damage)
	{
		health = HealthDamage(damage, health);
		return health;
	}

	public virtual void Death()
	{
		isDead = true;
		timeDeath = Time.time;
	}

	public bool IsDeadFrame()
	{
		return isDead && Mathf.Floor(timeDeath * 100f) != Mathf.Floor(Time.time * 100f);
	}
}
